<?php
$script = <<< JS

$('#zipCode').change(function(){
	var zipId = $(this).val();
	
	$.get('index.php?r = locat/get-city-province',{ zipId : zipId },funtion(data){
		var data = $.parseJSON(data);
		$('#customers-city').attr('value',data.city);
		$('#customers-province').attr('value',data.province);
		
	});
	
});
JS;
$this->registerJs($script);
?>




public function actionGetCityProvince($zipId){
	$locat = Location::findOne($zipId);
	echo Json::encode($locat);
}


<?= $form->field($model, 'zipcode')->widget(Select2::classname(), [
    'data' => ArrayHelper::map(Location:: find()->all(),'location_id', 'zipcode'),
    'language' => 'en',
    'options' => ['placeholder' => 'Select zipcode','id'=>'zipCode'],
    'pluginOptions' => [
        'allowClear' => true
    ],
]);?>

use yii\helpers\ArrayHelper;
use backend\models\Location;
use kartik\select2\Select2;


    <?= $form->field($model, 'zip_code')->dropDownList(ArrayHelper::map(Location::find()->all(), 'location_id', 'zip_code'),['prompt'=>'Select location', 'id'=>'customers-zip_code']) ?>
